package com.suli.multimedia.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author admin
 * @version 1.0 <br/>
 * <p style="font-family:SimSun;font-weight:bold">时间:<br/>2022/3/10 10:36</p>
 */
public class MessageUtil {
    public static String getMessage(boolean isSystem,String fromName,Object Message){
        ResultMessage resultMessage=new ResultMessage();
        resultMessage.setSystem(isSystem);
        resultMessage.setMessage(Message);
        if (fromName!=null)
            resultMessage.setFromName(fromName);
        ObjectMapper mapper=new ObjectMapper();
        try {
            return mapper.writeValueAsString(resultMessage);
        } catch (JsonProcessingException e) {
            System.out.println("消息封装失败："+"isSystem ："+isSystem+"fromName："+fromName+"Message："+Message);
            e.printStackTrace();
        }
        return null;
    }
}
